/**
 *
 * 2007-11-4 下午03:46:09
 * @author xuhuan
 */

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnViewNode;

public class ViewLoader extends NodeLoader {

	public List<Shape> loadNodes(Element root) {

		NodeList viewNodes = root
				.getElementsByTagName(SaturnViewNode.KEY_NODE_VIEW);

		List<Shape> shapes = new ArrayList<Shape>(viewNodes.getLength());

		for (int i = 0; i < viewNodes.getLength(); ++i) {
			SaturnViewNode saturnViewNode = new SaturnViewNode();
			Node viewNode = viewNodes.item(i);
			String shapeId = super.getNodeAttributeValue(viewNode,
					Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(viewNode,
					Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String name = super.getNodeElementValue(viewNode,
					SaturnViewNode.SHOW_VIEW_NODE_NAME);
			String description = super.getNodeElementValue(viewNode,
					SaturnViewNode.SHOW_VIEW_NODE_DESCRITPION);
			String type = super.getNodeElementValue(viewNode,
					SaturnViewNode.SHOW_VIEW_NODE_TYPE);
			String actionlocation = super.getNodeElementValue(viewNode,
					SaturnViewNode.SHOW_VIEW_NODE_LOCATION);

			Point location = super.getLocation(viewNode);
			Dimension size = new Dimension(50, 70);
			
			saturnViewNode.setNode(viewNode);
			saturnViewNode.setId(shapeId);
			saturnViewNode.setLocation(location);
			saturnViewNode.setName(name);
			saturnViewNode.setNextId(nextId);
			saturnViewNode.setDescription(description);
			saturnViewNode.setType(type);
			saturnViewNode.setActionlocation(actionlocation);
			saturnViewNode.setSize(size);

			shapes.add(saturnViewNode);
		}

		return shapes;
	}
}
